#include "Arduino.h"
#include "Button.h"

Button::Button(int PinButton, int PinSwitch)
{
    pinSwitch = PinSwitch;
	pinButton = PinButton;
	stateButton = 0;
	lastStateButton = 0;
	pushCounterButton = 0;	
}

void Button::push()
{
	pushCounterButton++;
}

void Button::check()
{
	stateButton = digitalRead(pinButton);
	
	if (stateButton != lastStateButton) 
		if (stateButton == HIGH)
			pushCounterButton++;
	  
	lastStateButton = stateButton;

	if (pushCounterButton % 2 == 0)
	{
		digitalWrite(pinSwitch, HIGH);
		pushCounterButton = 0;
	}  
	else
		digitalWrite(pinSwitch, LOW);	
}
